def minDepth(root):
    # 如果树为空，返回深度0
    if root is None:
        return 0

    # 如果当前节点是叶子节点，返回深度1
    if root.left is None and root.right is None:
        return 1

    # 如果左子树为空，递归计算右子树的最小深度并加1
    if root.left is None:
        return minDepth(root.right) + 1

    # 如果右子树为空，递归计算左子树的最小深度并加1
    if root.right is None:
        return minDepth(root.left) + 1

    # 如果左右子树都不为空，返回左右子树最小深度中的较小者并加1
    return min(minDepth(root.left), minDepth(root.right)) + 1


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


# 构建示例树
root = TreeNode(3)
root.left = TreeNode(9)
root.right = TreeNode(20)
root.right.left = TreeNode(15)
root.right.right = TreeNode(7)

# 找到并输出树的最小深度
min_depth = minDepth(root)
print(f"该二叉树的最小深度为：{min_depth}")